#include"eRtcDriver.h"


void eRtcDriverInit(void)
{
  RTC_InitStructure RTC_initStruct;
  RTC_DateTime dateTime;
  
  RTC_initStruct.Year = 2016;
  RTC_initStruct.Month = 5;
  RTC_initStruct.Date = 5;
  RTC_initStruct.Hour = 15;
  RTC_initStruct.Minute = 5;
  RTC_initStruct.Second = 5;
  RTC_initStruct.SecondIEn = 1;
  RTC_initStruct.MinuteIEn = 0;
  
  RTC_GetDateTime(RTC, &dateTime);
  if(dateTime.Year == 0)
  {
    RTC_Init(RTC, &RTC_initStruct);	
    
  }
  RTC_IntSecondEn(RTC);
  NVIC_EnableIRQ(RTC_IRQn);
  RTC_Start(RTC);
  
  
}


void RTC_Handler(void)
{
  RTC_DateTime dateTime;
  
  if(RTC_IntSecondStat(RTC))
  {
    RTC_IntSecondClr(RTC);
    
    RTC_GetDateTime(RTC, &dateTime);
//    printf("Now Time: %02d : %02d\r\n", dateTime.Minute, dateTime.Second);
    
    GPIO_InvBit(GPION, PIN8);
  }
}


RTC_DateTime  eRtcGetTimeInf(void)
{
  RTC_DateTime dateTime;
  
  RTC_GetDateTime(RTC, &dateTime);
  return dateTime;
  
}

